/**
 * 参数处理
 * @param {*} params  参数
 */
export function tansParams(params) {
  if (params) {
    let result = ''
    for (const propName of Object.keys(params)) {
      const value = params[propName]
      var part = encodeURIComponent(propName) + '='
      if (value !== null && value !== '' && typeof value !== 'undefined') {
        if (typeof value === 'object') {
          for (const key of Object.keys(value)) {
            if (value[key] !== null && value[key] !== '' && typeof value[key] !== 'undefined') {
              let params = propName + '[' + key + ']'
              var subPart = encodeURIComponent(params) + '='
              result += subPart + encodeURIComponent(value[key]) + '&'
            }
          }
        } else {
          result += part + encodeURIComponent(value) + '&'
        }
      }
    }
    result = result.slice(0, result.length - 1)
    return result
  } else {
    return ''
  }
}
/**
 * 判断设备类型
 * @returns {'android'|'ios'|'other'} 返回设备类型
 */
export function getDeviceType() {
  const ua = navigator.userAgent.toLowerCase()
  if (ua.indexOf('android') > -1 || ua.indexOf('adr') > -1) {
    return 'android'
  } else if (/iphone|ipad|ipod|ios/.test(ua)) {
    return 'ios'
  }
  return 'other'
}
